#ifndef SERIAL_H
#define SERIAL_H

#include <QMainWindow>
#include <QDebug>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QApplication>
#include <QObject>

#include "easytool.h"

class Serial : public QObject
{
    Q_OBJECT
public:
    typedef void (*SerialRecv)(QByteArray recv);

    enum SERIAL_RESULT
    {
        OK,
        FAIL,
    };

    SerialRecv serialRecv = NULL;
    QSerialPort serialPort;
    Serial();
    void printfInfo();
    QList<QSerialPortInfo> getSerialList();
    SERIAL_RESULT open(QSerialPortInfo info,QString Baud);
    SERIAL_RESULT close();
    QList<QString> getBaudList();
    void setRecv(SerialRecv recvFun);
    void send(char *buf,int len);
signals:
    void sendSignals(QByteArray arry);
private slots:
    void sendSlot(QByteArray arry);
    void readDataSlot();
    void errorSlot(QSerialPort::SerialPortError serialPortError);
};

#endif // SERIAL_H
